package day17.udp2;

import lombok.SneakyThrows;

import java.net.*;

public class Client {
    @SneakyThrows
    public static void main(String[] args) {
        try (DatagramSocket datagramSocket = new DatagramSocket(9528)) {
            while (true) {
                // 提示用户输入消息
                String inputMessage = UdpUtils.input();
                // 发消息出去
                UdpUtils.sendMessage(datagramSocket, inputMessage, UdpUtils.buildAddress(9527, "127.0.0.1"));
                // 收对方的消息
                String message = UdpUtils.receiveMessage(datagramSocket);
                if("byebye".equals(message)) break;
                System.out.println("[9528端收到消息]：" + message);
            }
        }
    }
}
